
//******************************对查询出来的火车票进行筛选 $(obj).attr("disabled","");
function formData()
{
	var typeB	=	document.getElementById("initials-B").checked;
	var typeZ	=	document.getElementById("initials-Z").checked;
	var typeD	=	document.getElementById("initials-D").checked;
	var typeO	=	document.getElementById("initials-O").checked;
	
	var AM	=	document.getElementById("AM").checked;

	var PM1	=	document.getElementById("PM1").checked;
	var PM2	=	document.getElementById("PM2").checked;
	

	var sign=false;
	if(typeD&&typeO)
	{
		var sign=true;
	}
	
	if(!typeD&&!typeO)
	{
		var sign=true;
	}	
	if(sign)
	{
		var Divs	=	document.getElementsByName("carnet");
		var length	=	Divs.length;


		for(var i=0;i<length;i++)
		{
			var time1=Divs[i].getAttribute("time1").replace(/:.*/,"");
			var time =parseInt(time1);
			var isZD = Divs[i].getAttribute("isZD");
			sign=true;
			
			
			if(AM&&time1>=12)
			{
				sign=false;
			}	
			if(PM1&&(time1<12||time1>18))
			{
				sign=false;
			}			
			if(PM2&&time1<=18)
			{
				sign=false;
			}
			if(typeB&&isZD==0&&!typeZ){
				sign=false;
			}
			if(typeZ&&isZD==1&&!typeB){
				sign=false;
			}
		
	
			if(sign)
			Divs[i].style.display="";
			else Divs[i].style.display="none";
		}	
	}
	else
	{
		var Divs	=	document.getElementsByName("carnet");
		var length	=	Divs.length;

		for(var i=0;i<length;i++)
		{
			var type =Divs[i].getAttribute("type").substring(0,1).toUpperCase().replace(/\d/,"L");
			var time1=Divs[i].getAttribute("time1").replace(/:.*/,"");
			var time =parseInt(time1);
			var isZD = Divs[i].getAttribute("isZD");
			sign=false;
			
			
			//车次类型
			if(!sign&&typeD&&type=="D")
			{
				sign=true;
			}	
			if(!sign&&typeO&&type!="D"){
				sign=true;
			}
			
			//出发时间
			if(sign){
				if(AM&&time1>=12)
				{
					sign=false;
				}	
				if(PM1&&(time1<12||time1>18))
				{
					sign=false;
				}			
				if(PM2&&time1<=18)
				{
					sign=false;
				}
			if(typeB&&isZD==0&&!typeZ){
				sign=false;
			}
			if(typeZ&&isZD==1&&!typeB){
				sign=false;
			}
			}

			//最后决定是否显示
			if(sign)
			{
				Divs[i].style.display="";
			}
			else
			{
				Divs[i].style.display="none";
			}
		}		
	}
}

//对验证码进行验证
function checkCode(){
	return true;
}



//******************************按条件查现有火车票dd
function DateAdd(strDate) {
    var dtArr = strDate.split('-');
    var d = new Date(dtArr[0], dtArr[1] - 1, dtArr[2]);
    d.setDate(d.getDate() + 1);
    var m = d.getMonth() + 1;
    var day = d.getDate();
    var curDateString = d.getFullYear() + "-" + (m < 10 ? "0" : "") + m + "-" + (day < 10 ? "0" : "") + day;
    return curDateString;
}

function search(startDate,startStation,arrivalStation){

	if(startStation.length == 0 || startStation == "请选择出发城市"){
		alert("请选择出发城市！");
		return;
	}
	if(arrivalStation.length == 0 || arrivalStation == "请选择到达城市"){
		alert("请选择到达城市！");
		return;
	}
	if(startDate.length == 0 || startDate == "请选择出行日期"){
		alert("请选择出行日期！");
		return;
	}
	/*if($("#searchvalidateCode").val().length == 0){
		alert("请填写验证码！");
		return;
	}*/
}

// 火车票查询需要验证验证码是否正确
function searchTrainInfo(){
	return search($("#date").val(),$("#begin").val(),$("#end").val());
}	


// 根据车次查询
function searchBytrainCode(trainCodeUrl,title){
	showPopWin(trainCodeUrl,title,800,600,false);
}
function addTrainInfo(arr,idx,item,startDate){
	
	var trainCode = item.trainCode.substring(0,1);		// 获取车次符号 D为动车标志
	var httpUrl = "web/ticket/bookticket/init.htm?";	// 非动车
	if(trainCode == "D")
		httpUrl = "web/ticket/bookticket/initD.htm?"	// 动车
	
	var sUrl = httpUrl +
		"trainInfo.trainCode="+item.trainCode+
		"&trainInfo.startStation="+item.startStation+
		"&trainInfo.arrivalStaion="+item.arrivalStaion+
		"&trainInfo.trainStartStation="+item.trainStartStation+
		"&trainInfo.trainArrivalStation="+item.trainArrivalStation+
		"&trainInfo.starttime="+item.starttime+
		"&trainInfo.arrivetime="+item.arrivetime+
		"&trainInfo.costtime="+item.costtime+
		"&trainInfo.trainType="+item.trainType+
		"&trainInfo.hardseat="+item.hardseat+
		"&trainInfo.hardseatTicket="+item.hardseatTicket+
		"&trainInfo.softseat="+item.softseat+
		"&trainInfo.softseatTicket="+item.softseatTicket+
		"&trainInfo.hardberth="+item.hardberth+
		"&trainInfo.hardberthTicket="+item.hardberthTicket+
		"&trainInfo.softberth="+item.softberth+
		"&trainInfo.softberthTicket="+item.softberthTicket+
		"&trainInfo.firstclass="+item.firstclass+
		"&trainInfo.firstclassTicket="+item.firstclassTicket+
		"&trainInfo.secondclass="+item.secondclass+
		"&trainInfo.secondclassTicket="+item.secondclassTicket+
		"&trainInfo.topSoftberth="+item.topSoftberth+
		"&trainInfo.topSoftberthTicket="+item.topSoftberthTicket+
		"&trainInfo.wzseat="+item.wzseat+
		"&trainInfo.wzseatTicket="+item.wzseatTicket+
		"&startDate=" + startDate;
	var cmdOrderButton = "<div align='center'><img style='cursor:hand' src='pages/website/images/yd1.gif' width='48' height='22' border='0' onclick='checkCurUser(\""+encodeURI(sUrl)+"\");'/></div>";
	var canOrder = item.canOrder;
	if(canOrder == 0){
		cmdOrderButton = "<div align='center'><img src='pages/website/images/yd2.gif' width='48' height='22'/></div>";
	}

			
	// 根据车次查询连接
	var trainCodeUrl = "web/ticket/searchticket/trainCode.htm?"+
		"dockStationByTrainCodeParam.trainCode="+item.trainCode+
		"&dockStationByTrainCodeParam.trainAllCode="+item.trainAllCode+
		"&startDate=" + startDate+
		"&trainType=" + item.trainType;
		
	var trainCodeTitle = item.trainCode + "列车车次时刻表"
	var cmdTrainCodeHref = "<a href='javascript:void(0);' onclick='searchBytrainCode(\""+encodeURI(trainCodeUrl)+"\",\""+trainCodeTitle+"\");'>"+item.trainCode+"</a><br/>"+item.trainStartStation+"-"+item.trainArrivalStation;
	
	
	// 硬座
	var hardseatDiv = "<div align='center'><span style='color:#1B67B5'>"+item.hardseat+"</span><br/><span style='color:#FF8B00'>"+item.hardseatTicket+"</span></div>";
	if(item.hardseatTicket == "0"){
		hardseatDiv = "<div align='center'><span style='color:#999999'>"+item.hardseat+"</span></div>";
	}
	
	// 软座
	var softseatDiv = "<div align='center'><span style='color:#1B67B5'>"+item.softseat+"</span><br/><span style='color:#FF8B00'>"+item.softseatTicket+"</span></div>";
	if(item.softseatTicket == "0"){
		softseatDiv = "<div align='center'><span style='color:#999999'>"+item.softseat+"</span></div>";
	}
	
	// 硬卧上/中/下
	var hardberthDiv = "<div align='center'><span style='color:#1B67B5'>"+item.hardberth+"</span><br/><span style='color:#FF8B00'>"+item.hardberthTicket+"</span></div>";
	if(item.hardberthTicket == "0"){
		hardberthDiv = "<div align='center'><span style='color:#999999'>"+item.hardberth+"</span></div>";
	}
	
	// 软卧上/下
	var softberthDiv = "<div align='center'><span style='color:#1B67B5'>"+item.softberth+"</span><br/><span style='color:#FF8B00'>"+item.softberthTicket+"</span></div>";
	if(item.softberthTicket == "0"){
		softberthDiv = "<div align='center'><span style='color:#999999'>"+item.softberth+"</span></div>";
	}
	
	// 一等座
	var firstclassDiv = "<div align='center'><span style='color:#1B67B5'>"+item.firstclass+"</span><br/><span style='color:#FF8B00'>"+item.firstclassTicket+"</span></div>";
	if(item.firstclassTicket == "0"){
		firstclassDiv = "<div align='center'><span style='color:#999999'>"+item.firstclass+"</span></div>";
	}
	
	// 二等座
	var secondclassDiv = "<div align='center'><span style='color:#1B67B5'>"+item.secondclass+"</span><br/><span style='color:#FF8B00'>"+item.secondclassTicket+"</span></div>";
	if(item.secondclassTicket == "0"){
		secondclassDiv = "<div align='center'><span style='color:#999999'>"+item.secondclass+"</span></div>";
	}
	
	// 高软
	var topclassDiv = "<div align='center'><span style='color:#1B67B5'>"+item.topSoftberth+"</span><br/><span style='color:#FF8B00'>"+item.topSoftberthTicket+"</span></div>";
	if(item.topSoftberthTicket == "0"){
		topclassDiv = "<div align='center'><span style='color:#999999'>"+item.topSoftberth+"</span></div>";
	}
	
	// 无座
	var wzseatDiv = "<div align='center'><span style='color:#1B67B5'>"+item.wzseat+"</span><br/><span style='color:#FF8B00'>"+item.wzseatTicket+"</span></div>";
	if(item.wzseatTicket == "0"){
		wzseatDiv = "<div align='center'><span style='color:#999999'>"+item.wzseat+"</span></div>";
	}
	
	
	var isZD = 0;	// 是否是直达列车[0不是 | 1是]
	if(item.startStation == item.trainStartStation){
		isZD = 1
	}
	
	arr.push(
		"<tr id='carnet' isZD="+isZD+" time1='"+item.starttime+"' type='"+item.trainCode+"'>"+
			"<td  height='48' class='line-xx'><div align='center'>"+cmdTrainCodeHref+"</div></td>"+
			"<td  height='48' class='line-xx' sortval='"+item.starttime+"'><div align='center'>"+item.startStation+"-"+item.arrivalStaion+"<br/>("+item.starttime+"-"+item.arrivetime+")</div></td>"+
			"<td  height='48' class='line-xx'><div align='center'>"+item.costtime+"</div></td>"+
			"<td  height='48' class='line-xx'>"+hardseatDiv+"</td>"+
			"<td  height='48' class='line-xx'>"+softseatDiv+"</td>"+
			"<td height='48' class='line-xx'>"+hardberthDiv+"</td>"+
			"<td  height='48' class='line-xx'>"+softberthDiv+"</td>"+
			"<td height='48' class='line-xx'>"+firstclassDiv+"</td>"+
			"<td  height='48' class='line-xx'>"+secondclassDiv+"</td>"+
			"<td height='48' class='line-xx'>"+topclassDiv+"</td>"+
			"<td height='48' class='line-xx'>"+wzseatDiv+"</td>"+
			"<td class='line-xx'>"+cmdOrderButton+"</td>"+
		"</tr>"
	);
}
